﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;

namespace ArgusLib.Fractals.OrbitFractals
{
	public class Parameter : IParameterIterations, IParameterShownArea
	{
		public int PixelWidth { get; set; }
		public int PixelHeight { get; set; }
		public ComplexArea ShownArea { get; set; }
		public int Iterations { get; set; }
		public int ThreadCount { get; set; }

		public Parameter(int pixelWidth, int pixelHeight)
		{
			this.PixelWidth = pixelWidth;
			this.PixelHeight = pixelHeight;
			this.ThreadCount = 0;
			this.ShownArea = new ComplexArea()
			{
				CenterRe = 0,
				CenterIm = 0,
				Width = 4,
				Height = 4,
				Rotation = 0
			};
			this.Iterations = 1000;
		}

		public Parameter Clone()
		{
			Parameter clone = new Parameter(this.PixelWidth, this.PixelHeight);
			clone.ShownArea = this.ShownArea;
			clone.Iterations = this.Iterations;
			return clone;
		}

		object ICloneable.Clone()
		{
			return this.Clone();
		}

		public Complex Convert(float x, float y)
		{
			double x2 = x - this.PixelWidth / 2.0;
			double y2 = this.PixelHeight / 2.0 - y;
			double re = x2 * this.ShownArea.Width / this.PixelWidth;
			double im = y2 * this.ShownArea.Height / this.PixelHeight;
			Complex rot = Complex.FromPolarCoordinates(1, -this.ShownArea.Rotation);
			Complex c = new Complex(re, im);
			return c * rot + this.ShownArea.Center;
		}

		object IParameter.Convert(float x, float y)
		{
			return this.Convert(x, y);
		}
	}
}
